{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from urllib.request import quote\n",
    "import requests\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getlnglat(address):\n",
    "    \"\"\"\n",
    "    获取一个中文地址的经纬度(lat:纬度值,lng:经度值)\n",
    "    \"\"\"\n",
    "    url_base = \"http://api.map.baidu.com/geocoder/v2/\"\n",
    "    output = \"json\"\n",
    "    ak = \"SaG5y6eI888RC0tLrk5O73XVfpcmdiKg\" # 浏览器端密钥\n",
    "    address = quote(address) # 由于本文地址变量为中文，为防止乱码，先用quote进行编码\n",
    "    url = url_base + '?' + 'address=' + address  + '&output=' + output + '&ak=' + ak \n",
    "    lat = 0.0\n",
    "    lng = 0.0\n",
    "    res = requests.get(url)\n",
    "    temp = json.loads(res.text)\n",
    "    if temp[\"status\"] == 0:\n",
    "        lat = temp['result']['location']['lat']\n",
    "        lng = temp['result']['location']['lng']\n",
    "    return lat,lng"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#用来正常显示中文标签\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "#用来正常显示负号\n",
    "plt.rcParams['axes.unicode_minus'] = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>totalprice</th>\n",
       "      <th>unitprice</th>\n",
       "      <th>position</th>\n",
       "      <th>rooms</th>\n",
       "      <th>size</th>\n",
       "      <th>orientation</th>\n",
       "      <th>decoration</th>\n",
       "      <th>elevator</th>\n",
       "      <th>area</th>\n",
       "      <th>height</th>\n",
       "      <th>year</th>\n",
       "      <th>buildtype</th>\n",
       "      <th>follow</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>920.0</td>\n",
       "      <td>77188</td>\n",
       "      <td>天悦龙庭二期</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>119.19</td>\n",
       "      <td>西南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>宝安中心</td>\n",
       "      <td>中</td>\n",
       "      <td>2005</td>\n",
       "      <td>塔楼</td>\n",
       "      <td>13</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>340.0</td>\n",
       "      <td>51909</td>\n",
       "      <td>大益广场</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>65.50</td>\n",
       "      <td>西南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>低</td>\n",
       "      <td>2002</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>160</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>660.0</td>\n",
       "      <td>73884</td>\n",
       "      <td>中熙香缇湾</td>\n",
       "      <td>4室2厅</td>\n",
       "      <td>89.33</td>\n",
       "      <td>西南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>中</td>\n",
       "      <td>2009</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>226</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1150.0</td>\n",
       "      <td>76657</td>\n",
       "      <td>深业新岸线三期</td>\n",
       "      <td>4室1厅</td>\n",
       "      <td>150.02</td>\n",
       "      <td>东南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>宝安中心</td>\n",
       "      <td>中</td>\n",
       "      <td>2008</td>\n",
       "      <td>塔楼</td>\n",
       "      <td>29</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>570.0</td>\n",
       "      <td>52127</td>\n",
       "      <td>碧海富通城一期</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>109.35</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>碧海</td>\n",
       "      <td>中</td>\n",
       "      <td>2006</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>54</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>530.0</td>\n",
       "      <td>44821</td>\n",
       "      <td>金港华庭</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>118.25</td>\n",
       "      <td>西南</td>\n",
       "      <td>简装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>中</td>\n",
       "      <td>2009</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>206</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>195.0</td>\n",
       "      <td>63169</td>\n",
       "      <td>碧海富通城四期</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>30.87</td>\n",
       "      <td>西南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>碧海</td>\n",
       "      <td>高</td>\n",
       "      <td>2009</td>\n",
       "      <td>板楼</td>\n",
       "      <td>214</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>488.0</td>\n",
       "      <td>52137</td>\n",
       "      <td>金成名苑</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>93.60</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>翻身</td>\n",
       "      <td>高</td>\n",
       "      <td>2001</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>83</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>510.0</td>\n",
       "      <td>100751</td>\n",
       "      <td>西岸观邸</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>50.62</td>\n",
       "      <td>南 西</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>宝安中心</td>\n",
       "      <td>低</td>\n",
       "      <td>2007</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>70</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>500.0</td>\n",
       "      <td>57340</td>\n",
       "      <td>灵芝新村</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>87.20</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>新安</td>\n",
       "      <td>中</td>\n",
       "      <td>1989</td>\n",
       "      <td>板楼</td>\n",
       "      <td>3</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>520.0</td>\n",
       "      <td>59085</td>\n",
       "      <td>招商果岭花园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>88.01</td>\n",
       "      <td>西北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>中</td>\n",
       "      <td>2012</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>106</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>740.0</td>\n",
       "      <td>78225</td>\n",
       "      <td>第五大道高发西岸花园三期</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>94.60</td>\n",
       "      <td>南 北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>宝安中心</td>\n",
       "      <td>中</td>\n",
       "      <td>2011</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>128</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>325.0</td>\n",
       "      <td>54312</td>\n",
       "      <td>绿海名苑</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>59.84</td>\n",
       "      <td>西北 北</td>\n",
       "      <td>简装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>低</td>\n",
       "      <td>2005</td>\n",
       "      <td>塔楼</td>\n",
       "      <td>89</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>335.0</td>\n",
       "      <td>55574</td>\n",
       "      <td>半岛明苑</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>60.28</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>中</td>\n",
       "      <td>1999</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>32</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>780.0</td>\n",
       "      <td>87435</td>\n",
       "      <td>勤诚达22世纪一期</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>89.21</td>\n",
       "      <td>东</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>新安</td>\n",
       "      <td>中</td>\n",
       "      <td>2013</td>\n",
       "      <td>塔楼</td>\n",
       "      <td>51</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>750.0</td>\n",
       "      <td>83603</td>\n",
       "      <td>中熙香缇湾</td>\n",
       "      <td>4室2厅</td>\n",
       "      <td>89.71</td>\n",
       "      <td>东南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>西乡</td>\n",
       "      <td>高</td>\n",
       "      <td>2009</td>\n",
       "      <td>板塔结合</td>\n",
       "      <td>111</td>\n",
       "      <td>宝安</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    totalprice  unitprice       position rooms    size orientation decoration  \\\n",
       "0        920.0      77188        天悦龙庭二期   3室2厅  119.19          西南         精装   \n",
       "1        340.0      51909          大益广场   2室2厅   65.50          西南         精装   \n",
       "2        660.0      73884         中熙香缇湾   4室2厅   89.33          西南         精装   \n",
       "3       1150.0      76657       深业新岸线三期   4室1厅  150.02          东南         精装   \n",
       "4        570.0      52127       碧海富通城一期   3室2厅  109.35           南         精装   \n",
       "5        530.0      44821          金港华庭   3室2厅  118.25          西南         简装   \n",
       "6        195.0      63169       碧海富通城四期   1室1厅   30.87          西南         精装   \n",
       "7        488.0      52137          金成名苑   3室2厅   93.60          东南         其他   \n",
       "8        510.0     100751          西岸观邸   2室1厅   50.62         南 西         其他   \n",
       "9        500.0      57340          灵芝新村   3室2厅   87.20          东南         其他   \n",
       "10       520.0      59085        招商果岭花园   3室2厅   88.01          西北         精装   \n",
       "11       740.0      78225  第五大道高发西岸花园三期   3室2厅   94.60         南 北         精装   \n",
       "12       325.0      54312          绿海名苑   2室2厅   59.84        西北 北         简装   \n",
       "13       335.0      55574          半岛明苑   2室1厅   60.28          东南         其他   \n",
       "14       780.0      87435     勤诚达22世纪一期   3室2厅   89.21           东         其他   \n",
       "15       750.0      83603         中熙香缇湾   4室2厅   89.71          东南         精装   \n",
       "\n",
       "   elevator  area height  year buildtype  follow city  \n",
       "0       有电梯  宝安中心      中  2005        塔楼      13   宝安  \n",
       "1       有电梯    西乡      低  2002      板塔结合     160   宝安  \n",
       "2       有电梯    西乡      中  2009      板塔结合     226   宝安  \n",
       "3       有电梯  宝安中心      中  2008        塔楼      29   宝安  \n",
       "4       有电梯    碧海      中  2006      板塔结合      54   宝安  \n",
       "5       有电梯    西乡      中  2009      板塔结合     206   宝安  \n",
       "6       有电梯    碧海      高  2009        板楼     214   宝安  \n",
       "7       有电梯    翻身      高  2001      板塔结合      83   宝安  \n",
       "8       有电梯  宝安中心      低  2007      板塔结合      70   宝安  \n",
       "9       无电梯    新安      中  1989        板楼       3   宝安  \n",
       "10      有电梯    西乡      中  2012      板塔结合     106   宝安  \n",
       "11      有电梯  宝安中心      中  2011      板塔结合     128   宝安  \n",
       "12      有电梯    西乡      低  2005        塔楼      89   宝安  \n",
       "13      无电梯    西乡      中  1999      板塔结合      32   宝安  \n",
       "14      有电梯    新安      中  2013        塔楼      51   宝安  \n",
       "15      有电梯    西乡      高  2009      板塔结合     111   宝安  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"数据加载\"\"\"\n",
    "house = pd.read_excel('house.xls', index_col=None)\n",
    "house.head(16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n",
      "50\n",
      "51\n",
      "52\n",
      "53\n",
      "54\n",
      "55\n",
      "56\n",
      "57\n",
      "58\n",
      "59\n",
      "60\n",
      "61\n",
      "62\n",
      "63\n",
      "64\n",
      "65\n",
      "66\n",
      "67\n",
      "68\n",
      "69\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "80\n",
      "81\n",
      "82\n",
      "83\n",
      "84\n",
      "85\n",
      "86\n",
      "87\n",
      "88\n",
      "89\n",
      "90\n",
      "91\n",
      "92\n",
      "93\n",
      "94\n",
      "95\n",
      "96\n",
      "97\n",
      "98\n",
      "99\n",
      "100\n",
      "101\n",
      "102\n",
      "103\n",
      "104\n",
      "105\n",
      "106\n",
      "107\n",
      "108\n",
      "109\n",
      "110\n",
      "111\n",
      "112\n",
      "113\n",
      "114\n",
      "115\n",
      "116\n",
      "117\n",
      "118\n",
      "119\n",
      "120\n",
      "121\n",
      "122\n",
      "123\n",
      "124\n",
      "125\n",
      "126\n",
      "127\n",
      "128\n",
      "129\n",
      "130\n",
      "131\n",
      "132\n",
      "133\n",
      "134\n",
      "135\n",
      "136\n",
      "137\n",
      "138\n",
      "139\n",
      "140\n",
      "141\n",
      "142\n",
      "143\n",
      "144\n",
      "145\n",
      "146\n",
      "147\n",
      "148\n",
      "149\n",
      "150\n",
      "151\n",
      "152\n",
      "153\n",
      "154\n",
      "155\n",
      "156\n",
      "157\n",
      "158\n",
      "159\n",
      "160\n",
      "161\n",
      "162\n",
      "163\n",
      "164\n",
      "165\n",
      "166\n",
      "167\n",
      "168\n",
      "169\n",
      "170\n",
      "171\n",
      "172\n",
      "173\n",
      "174\n",
      "175\n",
      "176\n",
      "177\n",
      "178\n",
      "179\n",
      "180\n",
      "181\n",
      "182\n",
      "183\n",
      "184\n",
      "185\n",
      "186\n",
      "187\n",
      "188\n",
      "189\n",
      "190\n",
      "191\n",
      "192\n",
      "193\n",
      "194\n",
      "195\n",
      "196\n",
      "197\n",
      "198\n",
      "199\n",
      "200\n",
      "201\n",
      "202\n",
      "203\n",
      "204\n",
      "205\n",
      "206\n",
      "207\n",
      "208\n",
      "209\n",
      "210\n",
      "211\n",
      "212\n",
      "213\n",
      "214\n",
      "215\n",
      "216\n",
      "217\n",
      "218\n",
      "219\n",
      "220\n",
      "221\n",
      "222\n",
      "223\n",
      "224\n",
      "225\n",
      "226\n",
      "227\n",
      "228\n",
      "229\n",
      "230\n",
      "231\n",
      "232\n",
      "233\n",
      "234\n",
      "235\n",
      "236\n",
      "237\n",
      "238\n",
      "239\n",
      "240\n",
      "241\n",
      "242\n",
      "243\n",
      "244\n",
      "245\n",
      "246\n",
      "247\n",
      "248\n",
      "249\n",
      "250\n",
      "251\n",
      "252\n",
      "253\n",
      "254\n",
      "255\n",
      "256\n",
      "257\n",
      "258\n",
      "259\n",
      "260\n",
      "261\n",
      "262\n",
      "263\n",
      "264\n",
      "265\n",
      "266\n",
      "267\n",
      "268\n",
      "269\n",
      "270\n",
      "271\n",
      "272\n",
      "273\n",
      "274\n",
      "275\n",
      "276\n",
      "277\n",
      "278\n",
      "279\n",
      "280\n",
      "281\n",
      "282\n",
      "283\n",
      "284\n",
      "285\n",
      "286\n",
      "287\n",
      "288\n",
      "289\n",
      "290\n",
      "291\n",
      "292\n",
      "293\n",
      "294\n",
      "295\n",
      "296\n",
      "297\n",
      "298\n",
      "299\n",
      "300\n",
      "301\n",
      "302\n",
      "303\n",
      "304\n",
      "305\n",
      "306\n",
      "307\n",
      "308\n",
      "309\n",
      "310\n",
      "311\n",
      "312\n",
      "313\n",
      "314\n",
      "315\n",
      "316\n",
      "317\n",
      "318\n",
      "319\n",
      "320\n",
      "321\n",
      "322\n",
      "323\n",
      "324\n",
      "325\n",
      "326\n",
      "327\n",
      "328\n",
      "329\n",
      "330\n",
      "331\n",
      "332\n",
      "333\n",
      "334\n",
      "335\n",
      "336\n",
      "337\n",
      "338\n",
      "339\n",
      "340\n",
      "341\n",
      "342\n",
      "343\n",
      "344\n",
      "345\n",
      "346\n",
      "347\n",
      "348\n",
      "349\n",
      "350\n",
      "351\n",
      "352\n",
      "353\n",
      "354\n",
      "355\n",
      "356\n",
      "357\n",
      "358\n",
      "359\n",
      "360\n",
      "361\n",
      "362\n",
      "363\n",
      "364\n",
      "365\n",
      "366\n",
      "367\n",
      "368\n",
      "369\n",
      "370\n",
      "371\n",
      "372\n",
      "373\n",
      "374\n",
      "375\n",
      "376\n",
      "377\n",
      "378\n",
      "379\n",
      "380\n",
      "381\n",
      "382\n",
      "383\n",
      "384\n",
      "385\n",
      "386\n",
      "387\n",
      "388\n",
      "389\n",
      "390\n",
      "391\n",
      "392\n",
      "393\n",
      "394\n",
      "395\n",
      "396\n",
      "397\n",
      "398\n",
      "399\n",
      "400\n",
      "401\n",
      "402\n",
      "403\n",
      "404\n",
      "405\n",
      "406\n",
      "407\n",
      "408\n",
      "409\n",
      "410\n",
      "411\n",
      "412\n",
      "413\n",
      "414\n",
      "415\n",
      "416\n",
      "417\n",
      "418\n",
      "419\n",
      "420\n",
      "421\n",
      "422\n",
      "423\n",
      "424\n",
      "425\n",
      "426\n",
      "427\n",
      "428\n",
      "429\n",
      "430\n",
      "431\n",
      "432\n",
      "433\n",
      "434\n",
      "435\n",
      "436\n",
      "437\n",
      "438\n",
      "439\n",
      "440\n",
      "441\n",
      "442\n",
      "443\n",
      "444\n",
      "445\n",
      "446\n",
      "447\n",
      "448\n",
      "449\n",
      "450\n",
      "451\n",
      "452\n",
      "453\n",
      "454\n",
      "455\n",
      "456\n",
      "457\n",
      "458\n",
      "459\n",
      "460\n",
      "461\n",
      "462\n",
      "463\n",
      "464\n",
      "465\n",
      "466\n",
      "467\n",
      "468\n",
      "469\n",
      "470\n",
      "471\n",
      "472\n",
      "473\n",
      "474\n",
      "475\n",
      "476\n",
      "477\n",
      "478\n",
      "479\n",
      "480\n"
     ]
    },
    {
     "ename": "JSONDecodeError",
     "evalue": "Expecting value: line 1 column 1 (char 0)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mJSONDecodeError\u001b[0m                           Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-658952d5ccd9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     10\u001b[0m     \u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     11\u001b[0m     \u001b[0mcity\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcity\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m     \u001b[0mlat\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlng\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetlnglat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"深圳市\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mcity\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     13\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mlat\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mlng\u001b[0m \u001b[1;33m!=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m         \u001b[0midint\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0midi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m<ipython-input-7-9933de104fe2>\u001b[0m in \u001b[0;36mgetlnglat\u001b[1;34m(address)\u001b[0m\n\u001b[0;32m     11\u001b[0m     \u001b[0mlng\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m     \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m     \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     14\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"status\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m         \u001b[0mlat\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'result'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'location'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'lat'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\json\\__init__.py\u001b[0m in \u001b[0;36mloads\u001b[1;34m(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[0;32m    352\u001b[0m             \u001b[0mparse_int\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mparse_float\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    353\u001b[0m             parse_constant is None and object_pairs_hook is None and not kw):\n\u001b[1;32m--> 354\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0m_default_decoder\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    355\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mcls\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    356\u001b[0m         \u001b[0mcls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mJSONDecoder\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self, s, _w)\u001b[0m\n\u001b[0;32m    337\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    338\u001b[0m         \"\"\"\n\u001b[1;32m--> 339\u001b[1;33m         \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraw_decode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    340\u001b[0m         \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    341\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mraw_decode\u001b[1;34m(self, s, idx)\u001b[0m\n\u001b[0;32m    355\u001b[0m             \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mscan_once\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    356\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 357\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mJSONDecodeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Expecting value\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    358\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)"
     ]
    }
   ],
   "source": [
    "\"\"\"生成经纬度信息\"\"\"\n",
    "idint = []\n",
    "names = []\n",
    "lats = []\n",
    "lngs = []\n",
    "lat_lng_data = {\"id\":idint,\"communityName\":names,\"lat\":lats,\"lng\":lngs}\n",
    "\n",
    "#flag = 0\n",
    "for idi,name,city in zip(list(range(10106)),list(house[\"position\"]),list(house['city'])):\n",
    "    name = str(name)\n",
    "    city = str(city)\n",
    "    lat,lng = getlnglat(\"深圳市\"+city+name)\n",
    "    if lat != 0 or lng !=0:\n",
    "        idint.append(idi)\n",
    "        names.append(name)\n",
    "        lats.append(lat)\n",
    "        lngs.append(lng)\n",
    "        print(idi)\n",
    "    \n",
    "frame_test = pd.DataFrame(lat_lng_data)\n",
    "frame_test.to_csv(\"latlng.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
